package com.granada.model.pc;

import com.github.pagehelper.PageHelper;
import com.granada.entity.Ao;
import com.granada.entity.Page;
import com.granada.entity.SysRole;
import com.granada.model.common.Role;
import com.granada.utils.PageUtils;
import com.granada.vo.req.RoleAddReqVO;
import com.granada.vo.req.RolePageReqVO;
import com.granada.vo.resp.PageVO;
import com.granada.utils.MapperBeanUtils;

import java.util.Date;
import java.util.List;


public  class RoleWithBig<T extends SysRole,R extends RoleAddReqVO,F extends Page>  extends Role<T,R,F> {
    public RoleWithBig(T vo, R ro, F fo, Ao ao) {
        super(vo, ro, fo, ao);
    }

    @Override
    public Long addRoleBefore() throws Exception {
        SysRole sysRole = SysRole.builder()
                .id(null)
                .name(vo.getName())
                .description(vo.getDescription())
                .status(vo.getStatus())
                .createTime(new Date())
                .build();
        MapperBeanUtils.getSysRoleMapper().insert(sysRole);
        return sysRole.getId();
    }

    @Override
    public void addRoleAfter() throws Exception {
    }


    @Override
    public void updateRoleAfter() throws Exception {
    }


    @Override
    public T getOne() throws Exception {
        T sysRoles = (T) MapperBeanUtils.getSysRoleMapper().selectByPrimaryKey(ao.id);
        return sysRoles;
    }

    @Override
    public T getSearchOne() throws Exception {
        return null;
    }

    @Override
    public List<T> getAll() throws Exception {
        return null;
    }

    @Override
    public List<T> getSearchAll() throws Exception {
        return null;
    }

    @Override
    public PageVO<T> getList() throws Exception {
        PageHelper.startPage(fo.getPageNum(),fo.getPageSize());
        List<T> sysRoles = (List<T>) MapperBeanUtils.getSysRoleMapper().bigPageInfo((RolePageReqVO) vo);
        return PageUtils.getPageVO(sysRoles);
    }

    @Override
    public PageVO<T> getSearchList() throws Exception {
        return null;
    }



}
